/*
 * Copyright (c) 2022, tyustli
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-17     tyustli      first implementation
 */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* 输入某年某月某日，判断这一天是这一年的第几天？ */

char month_day_array[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int calc_func(int year, int month, int day)
{
    int num = 0;
    char leap = 0;

    for (int i = 1; i < month; i++)
    {
        num += month_day_array[i];
    }

    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
    { // 判断是不是闰年
        leap = 1;
    }
    else
    {
        leap = 0;
    }
    if (leap == 1 && month > 2)
    { // *如果是闰年且月份大于2,总天数应该加一天
        num++;
    }

    num += day;

    return num;
}

int main(int argc, char *argv[])
{
    int year, month, day;
    printf("输入 年 月 日：\r\n");

    scanf("%d %d %d", &year, &month, &day);
    printf("输入的数据为：%d %d %d\r\n", year, month, day);

    int num = 0;
    num = calc_func(year, month, day);
    printf("输入的年月日当前的天数为：%d\r\n", num);

    return 0;
}

/************************ end of time ************************/
